<?php session_start(); 
if ( $_SESSION["level"] == null ) header("location:login.php");
?>
<!DOCTYPE html>
<html>
 <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <link rel="shortcut icon" href="./files/img/favicon.ico">
  <title>IAD - Euromedica</title>

  <link type="text/css" href="./files/jquery-ui/css/smoothness/jquery-ui-1.8.16.custom.css" rel="Stylesheet" />	
  <script type="text/javascript" src="./files/jquery-1.6.4.js"></script>
  <script type="text/javascript" src="./files/jquery-ui/js/jquery-ui-1.8.16.custom.min.js"></script>
  <script type="text/javascript" src="./files/padolsey-jQuery-Plugins-01abd79/sortElements/jquery.sortElements.js"></script>

  <style type="text/css">
    @import "style2.css";
  </style>

  <script type="text/javascript" src="./scripts.js"></script>
</head>
 <?php 
   include 'sql.php';
   $field = $_GET['field'];
   $filter = $_GET['filter'];
 ?>

<body>

<div id="access">
  <?php showRightPanel(); ?>
</div> <!--End of access-->

  <!--
  Start Header Area
  -->
<div id="header">
</div><!-- End of HEADER -->

<div id="ribbon">
  <table>
    <tr>

    </tr>
  </table>
</div><!--End of ribbon-->

 <!--
  Start Left Panel Area
  -->
 <?php showLeftPanel($_SESSION['level'], $_SESSION['user']); ?>
    <!--
    End of Left_panel
    -->

 <!--
  Start Container Area
  -->
 <div id="container">
  <div id="content"><!-- Content Area-->
    <div id="patients_table">
      <?php showFiltersOnomastiko($field); ?>
      <table id="team" class="patients_table">
	<h1><?php echo $filter?></h1>
	<?php $count = showOnomastikoDaily($field, $filter); ?>
	<?php if($_SESSION['level'] == "admin") { ?>
	<input type="button" id="check" name="Check" value="Delete All" style="margin: 0 auto;"<?php if( $count == 0){?> disabled="disabled"<?php }//end of if ?> >
	 <div id="dialog-delete" class="<?php echo $filter; ?>" hidden>
	    <p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>These items will be permanently deleted and cannot be recovered. Are you sure?</p>
	 </div>
	  <?php } // end of if?>
      </table>
      <div id="dialog-history" hidden>
	  <form id="showHistory">
	  <fieldset>
	    <label for="categ">Κατηγορία:</label><br>
	      <select id="category" name="category">
		<option value="approved" label="">Approved</option>
		<option value="ready" label="">Ready</option>
		<option value="pending" label="">Pending</option>
		<option value="rejected" label="">Rejected</option>
		<option value="misc" label="">Misc</option>
	      </select><br>
	    <label for="req_name">Ονοματεπώνυμο:</label><br>
	    <input type="text" name="req_name" id="req_name" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="pass_num">Αρ. Διαβατηρίου:</label><br>
	    <input type="text" name="pass_number" id="pass_number" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="clinic">Μονάδα:</label><br>
	    <input type="text" name="clinic" id="clinic" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="addm_num">Αρ. Εισαγωγής:</label><br>
	    <input type="text" name="addm_num" id="addm_number" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="pat_code">Κωδ. Ασθενούς:</label><br>
	    <input type="text" name="pat_code" id="patient_code" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="doctor">Υπεύθυνος Ιατρός:</label><br>
	    <input type="text" name="doctor" id="doctor" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="request">Αίτημα:</label><br>
	    <input type="text" name="request" id="req" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="est_cost">Εκτ. Κόστος:</label><br>
	    <input type="text" name="est_cost" id="estimated_cost" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="date_received">Ημ/νία Παραλαβής:</label><br>
	    <input type="text" name="date_received" id="date_rec" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="date_approved">Ημ/νία Έγκρισης:</label><br>
	    <input type="text" name="date_approved" id="date_app" class="text ui-widget-content ui-corner-all" /><br>
	    <label for="notes">Παρατηρήσεις:</label><br>
	    <input type="text" name="notes" id="observations" class="text ui-widget-content ui-corner-all" /><br>
	    <br>
	  </fieldset>
	</form>
	</div>
      </div>
  </div><!--END of content-->
</div><!--END of container-->

<?php showFooter(); ?><!--END of footer-->

<!-- Edit the note column -->
<script>
   $(document).ready(function() {
     var flag = true;
     $(".edit_tr").hover(function() { 
      var id = $(this).attr('id'); 
      $("#edit-btn-"+id).click(function() {
	$("#unit-"+id).hide();
	$("#unit-input-"+id).show();
	$("#location-"+id).hide();
	$("#location-input-"+id).show();
	$("#outpatient_of-"+id).hide();
	$("#outpatient_of-input-"+id).show();
	$("#departed-"+id).hide();
	$("#departed-input-"+id).show();
	$("#notes-"+id).hide();
	$("#notes-input-"+id).show();
      }); // end of click
     }).change(function() {
	  var id = $(this).attr('id');
	  var unit = $("#unit-input-"+id).val();
	  var location = $("#location-input-"+id).val();
	  var outpatient_of = $("#outpatient_of-input-"+id).val();
	  var notes = $("#notes-input-"+id).val();
	  var departed = $("#departed-input-"+id).val();
	  var dataString = 'patient_id=' + id + '&unit=' + unit + '&location=' + location + '&outpatient_of=' + outpatient_of + '&departed=' + departed +'&notes=' + notes;

	  $.ajax({
	  type: "POST",
	  url: "sql.php",
	  data: dataString,
	  cache: false,
	  success: function(html) {
	    $("#unit-"+id).html(unit);
	    $("#location-"+id).html(location);
	    $("#outpatient_of-"+id).html(outpatient_of);
	    $("#departed-"+id).html(departed);
	    $("#notes-"+id).html(notes);
	  }
	}); //end of ajax
	}); // end of change
      $(".editbox").mouseup(function() {
	return false;
      }); // end of mouseup
      // Outside click action
      $(document).mouseup(function() {
	$(".editbox").hide();
	$(".text").show();
      }); // end of mouseup
      $(document).hover(function(){
	var id=$(this).attr('id');
	$("#edit-"+id).hide();
	$("#delete-"+id).hide();
      });// end of hover
 });
</script>

<!-- Sort table -->
<script>
   $(document).ready(function() {
    var table = $('.patients_table');
    $('#sn, #name, #pass_num, dob, #med_unit, #addm_num, #pat_code, #doc_name, #request, #est_cost, #notes')
        .wrapInner('<span title="sort this column"/>')
        .each(function(){ 
            var th = $(this),
                thIndex = th.index(),
                inverse = false;
            th.click(function(){ 
                table.find('td').filter(function(){
                    return $(this).index() === thIndex;
                }).sortElements(function(a, b){ 
                    return $.text([a]) > $.text([b]) ?
                        inverse ? -1 : 1
                        : inverse ? 1 : -1;
                }, function(){
                    // parentNode is the element we want to move
                    return this.parentNode;      
                });              
                inverse = !inverse;     
            });               
        });
 });
</script>

<!-- Delete all patients -->
<script>
  $(document).ready(function() {
  $("#check").click(function() {
  var patients = $("#dialog-delete").attr('class');
  var f = false;
    $( "#dialog:ui-dialog" ).dialog( "destroy" );
      $( "#dialog-delete" ).dialog({
	title: "Delete all patients?",
	resizable: false,
	height:200,
	modal: true,
	buttons: {
	  "Delete all items": function() {
	    f = true;
	    $(this).dialog("close");
	    $(".edit_tr").each(function(index){
	      var id = $(this).attr('id');
	      $(this).hide();
	    });
	    // disable the delete all button
	    $("#check").attr('disabled', 'disabled');
	    if(f == true) {
	      // TO DO -> change it back to del_team_name
	      var dataString = 'pat_id='+patients;
	      $.ajax({
	      type: "POST",
	      url: "sql.php",
	      data: dataString,
	      cache: false,
	      success: function(html) {
	      }

	    });
	    }//end of if
	  },
	  Cancel: function() {
	    f = false;
	    $(this).dialog("close");
	  }//end of Cancel
	}//end of buttons
      });
  });
});
</script>

<script>
$(document).ready(function(){
  var flag = false;
  $(".edit_tr").hover(function() {
      var id = $(this).attr('id');
      $("#del-btn-"+id).show();
      $("#del-btn-"+id).click(function(){
	flag = true;
	$("#"+id).remove();
       var dataString = 'delete_id='+id;
 
       $.ajax({
 	type: "POST",
 	url: "sql.php",
 	data: dataString,
 	cache: false,
 	success: function(html) {
 	}
       });
      });//end of click for #delete
   },
   function(){
    var id = $(this).attr('id');
     flag = false;
//      $("#del-btn-"+id).hide();
  });//end of hover

// Show history of a patient
//  $(".edit_tr").click(function() {
//     var ID=$(this).attr('id'); 
//     $("#dialog:ui-confirm").dialog("destroy");
//     $("#dialog-history").dialog({
// 	title: "Δώστε τα στοιχεία:",
// 	resizable: false,
// 	height:560,
// 	width:400,
// 	modal: true,
// 	buttons:
// 	"OK": function(){
// 	  $.ajax({
// 	    url: "sql.php",
// 	    type: "POST",
// 	    data: $(this).find('form').serialize(),
// 	    success: function(data){
// 	      //some logic to show that the data was updated
// 	      //then close the window
// 	      $(this).dialog('close');
// 	    }
// 	  });
// 	},
// 	"Cancel" : function(){
// 	  $(this).dialog('close');
// 	}
//       });
// 
//     $.ajax({
//       url: "sql.php",
//       type: 'GET',
//       data: ID,
//       success: function(data){
// 	$("#dialog-history").html(data);
// 	$("#dialog-history").dialog('open');
//       }
// 
//     }); /*alert(ID);*/
//   });// end of show History 

});
</script>
</body>
</html>